﻿package mortal.game.scene3D.buff
{
    import Message.BroadCast.*;
    import Message.DB.Tables.*;
    import Message.Public.*;
    import flash.utils.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.player.entity.*;

    public class BuffChainUtil extends Object
    {
        public static const CONNECT:String = "#";
        public static var dicBuffStrToBuffChain:Dictionary = new Dictionary();

        public function BuffChainUtil()
        {
            return;
        }// end function

        public static function addChain(param1:String, param2:SpritePlayer, param3:SBuffInfo) : void
        {
            var _loc_4:* = param3.buffId.toString() + CONNECT + param2.entityID;
            if (!dicBuffStrToBuffChain[_loc_4])
            {
                dicBuffStrToBuffChain[_loc_4] = new ChainEffect(param1, param2, param3.fromEntityIds[0]);
            }
            return;
        }// end function

        public static function removeChain(param1:SpritePlayer, param2:SBuffInfo) : void
        {
            var _loc_4:ChainEffect = null;
            var _loc_3:* = param2.buffId.toString() + CONNECT + param1.entityID;
            if (dicBuffStrToBuffChain[_loc_3])
            {
                _loc_4 = dicBuffStrToBuffChain[_loc_3];
                _loc_4.dispose();
                delete dicBuffStrToBuffChain[_loc_3];
            }
            return;
        }// end function

        public static function removePlayerAllChains(param1:SpritePlayer) : void
        {
            var _loc_2:Array = null;
            var _loc_3:int = 0;
            var _loc_4:SBuffInfo = null;
            var _loc_5:TBuff = null;
            if (param1 && param1.entityInfo)
            {
                _loc_2 = param1.entityInfo.entityInfo.buffInfos;
                if (!_loc_2)
                {
                    return;
                }
                _loc_3 = 0;
                while (_loc_3 < _loc_2.length)
                {
                    
                    _loc_4 = _loc_2[_loc_3] as SBuffInfo;
                    _loc_5 = BuffConfig.instance.getInfoById(_loc_4.buffId);
                    if (_loc_5.type == EBuffType._EBuffTypeChain && _loc_4.fromEntityIds.length)
                    {
                        removeChain(param1, _loc_4);
                    }
                    _loc_3++;
                }
            }
            return;
        }// end function

        public static function clearAll() : void
        {
            var _loc_1:String = null;
            var _loc_2:ChainEffect = null;
            for (_loc_1 in dicBuffStrToBuffChain)
            {
                
                _loc_2 = dicBuffStrToBuffChain[_loc_1];
                _loc_2.dispose();
                delete dicBuffStrToBuffChain[_loc_1];
            }
            return;
        }// end function

    }
}
